<%--
  Created by IntelliJ IDEA.
  User: ZhuChunXiao
  Date: 2017/6/2
  Time: 9:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<div class="row">
  <div class="col-lg-12">
    <div class="panel">
      <div class="panel-heading header">
        <h3 class="panel-title" id="title">订单实施表</h3>
      </div>

      <div style="margin: 10px">

        <!-- Nav tabs -->
        <ul class="nav nav-tabs">
          <li class="active"><a id="other1" href="#s1" data-toggle="tab">基本信息</a></li>
          <li class="disabled"><a id="other2" href="#s2" data-toggle="tab">实时跟踪</a></li>
          <li class="disabled"><a id="other3" href="#s3" data-toggle="tab">完成确认</a></li>
        </ul>

        <!-- Tabs Content -->
        <div class="tab-content">
          <input type="hidden" id="tableWidth" />

          <div class="tab-pane pad-btm fade in active" id="s1">

              <!-- BASIC FORM ELEMENTS -->
              <!--===================================================-->
              <form id="form_order_input" class="panel-body form-horizontal form-padding">
                <input type="hidden" name="keyId" id="keyId" value="${order.id}" />
                <input type="hidden" name="curDutyId" id="curDutyId" value=""/>


                <div class="form-group" id="tempWidth">
                  <label class="col-md-2 control-label">订单合同<i class="fa fa-asterisk txt-color-red"></i></label>
                  <div class="col-md-6">
                    <input disabled type="text" id="contract" name="contract" class="form-control" placeholder="TODO" value="">
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-md-2 control-label">订单客户<i class="fa fa-asterisk txt-color-red"></i></label>
                  <div class="col-md-6">
                    <input disabled type="text" id="customer" name="customer" class="form-control" value="${order.name}">
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-md-2 control-label">订单编号<i class="fa fa-asterisk txt-color-red"></i></label>
                  <div class="col-md-6">
                    <input disabled type="number" id="orderNo" name="orderNo" class="form-control" placeholder="请输入订单编号" value="${order.orderNo}">
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-md-2 control-label">订单金额<i class="fa fa-asterisk txt-color-red"></i></label>
                  <div class="col-md-6">
                    <input disabled type="number" id="money" name="money" class="form-control" placeholder="请输入订单金额" value="${money}">
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-md-2 control-label">订单具体需求<i class="fa fa-asterisk txt-color-red"></i></label>
                  <div class="col-md-6">
                    <input disabled type="text" id="content" name="content" class="form-control" placeholder="请输入订单具体需求" value="${order.content}">
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-md-2 control-label">相关附件<i class="fa fa-asterisk txt-color-red"></i></label>
                  <div class="col-md-6">
                    <input name="uploadify" id="filename" style="display: none"  placeholder="" type="file" >
                    <input name="fileId" id="fileId" style="display: none" value="${fileId}">
                  </div>
                </div>

                <div class="form-group div-Hidden">
                  <label class="col-md-2 control-label">订单下达时间<i class="fa fa-asterisk txt-color-red"></i></label>
                  <div class="col-md-6">
                    <div class="input-group date">
                      <input disabled type="text" class="form-control" id="issuedDate" name="issuedDate" placeholder="请选择订单下达时间"
                             value=<fmt:formatDate pattern="yyyy-MM-dd" value="${order.issuedDate}" /> >
                      <span class="input-group-addon"><i class="ti-calendar"></i></span>
                    </div>
                  </div>
                </div>

                <div class="form-group div-Hidden">
                  <label class="col-md-2 control-label">期望交付时间<i class="fa fa-asterisk txt-color-red"></i></label>
                  <div class="col-md-6">
                    <div class="input-group date">
                      <input disabled type="text" class="form-control" id="deliverDate" name="deliverDate" placeholder="请选择期望交付时间"
                             value=<fmt:formatDate pattern="yyyy-MM-dd" value="${order.deliverDate}" /> >
                      <span class="input-group-addon"><i class="ti-calendar"></i></span>
                    </div>
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-md-2 control-label">备注</label>
                  <div class="col-md-6">
                    <input disabled type="text" id="remarks" name="remarks" class="form-control" placeholder="请输入备注" value="${order.remarks}">
                  </div>
                </div>


                <div class="form-group">
                  <label class="col-md-2 control-label">提交人</label>
                  <div class="col-md-2">
                    <p class="form-control-static">${order.creater.name}</p>
                  </div>
                  <label class="col-md-2 control-label">提交日期</label>
                  <div class="col-md-2">
                    <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${order.createTime}" /></p>
                  </div>
                </div>

                <c:if test='${(order.processState=="Running" || order.processState=="Backed") && stepNo !=1 && stepNo !=0}'>
                  <div class="form-group" id="comment">
                    <label class="col-md-2 control-label">审批意见</label>
                    <div class="col-md-6">
                      <textarea name="editor" id="editor" style="height:200px;"></textarea>
                    </div>
                  </div>
                </c:if>

                <div class="flow">
                  <div class="panel-footer">
                    <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                      <i class="fa fa-lg fa-mail-reply"></i> 返回
                    </a>
                    <a class="btn btn-default" key="ajax_edit" href="javascript:void(0);" ${isEdit}>
                      <i class="fa fa-lg fa-edit"></i> 编辑
                    </a>
                  </div>

                  <div class="f_title"><i class="right" id="flow"></i>流程信息</div>
                  <div class="f_content" style="display:none">
                    <div id="showFlow"></div>
                  </div>
                  <div class="f_title"><i class="right" id="next"></i>下一步骤提示</div>
                  <div class="f_content" style="display:none">
                    <div id="showNext"></div>
                  </div>
                </div>

              </form>
              <!--===================================================-->
              <!-- END BASIC FORM ELEMENTS -->

          </div>
          <div class="tab-pane fade" id="s2">2</div>
          <div class="tab-pane fade" id="s3">3</div>

        </div>
      </div>
    </div>
  </div>
</div>

<script>
  var state = "${order.processState}";
  var index = "${index}";
  var todo = "${todo}";
  var remind = "${remind}";
  var record = "${record}";
  var draft =  "${draft}";
  var stepNo = "${stepNo}";

  if(state == "Finished"){
    $('#other2').parent('li').removeClass('disabled');
    $('#other3').parent('li').removeClass('disabled');
  }

  $(function(){

    //如果是从订单页面点新建订单跟踪进来的话...
    var track="${track}";
    if(track==1){
      $("#other2").click();
      loadURL('<%=path%>/com/orderTrack/input?parentId='+$("#form_order_input #keyId").val(), $('#s2'));
    }

    loadURL("<%=path%>/com/running/workflow?bussinessId="+$("input#keyId").val()+"&type=flow",$('#showFlow'));
    loadURL("<%=path%>/com/running/workflow?bussinessId="+$("input#keyId").val()+"&type=next",$('#showNext'));
    __ajax_post("<%=path%>/com/running/operateType",{keyId: $("input#keyId").val()},function(pdata){
      var showDuty = false;
      var area = $("form .panel-footer");
      var edit = null;
      if (stepNo == 1){
        return false;
      }
      $(pdata.datarows).each(function(i,v){
        var str = '<a id="left_foot_btn_'+ v.action+'" class="btn btn-warning" href="javascript:void(0);"><i class="fa fa-upload">'+ v.name+'</i></a>&nbsp;';
        $(area).append(str);
        if(v.action == "approve" || v.action=="sendback"  || v.action=="deny"){
          showDuty = true;
        }
      });
      if(showDuty == true){
        var pdata = {
          keyId: $("input#keyId").val(),
          entityName: "com.fz.us.oa.core.entity.com.OrderEntity"
        };
        multiDuty(pdata);
      }else{
        $('#comment').hide();
      }
      if($(':visible#editor').length == 1){
        edit  = new UE.ui.Editor();
        edit.render('editor');
        /*
         edit.ready(function() {
         edit.setContent("");
         });*/
      }
      //通过
      $("#left_foot_btn_approve").off("click").on("click",function(){
        var comment = "";
        if(edit != null){
          comment = encodeURIComponent(edit.getContent());
        }
        if($.trim(comment) == ""){
          alert("请填写审批意见");
          return false;
        }
        __form_save("form_order_input","<%=path%>/com/orderEntity/approve?comment="+comment,function(){
          $("#apply-re-common").trigger("click");
        })
      });
      //退回
      $("#left_foot_btn_sendback").off("click").on("click",function(){
        var comment = "";
        if(edit != null){
          comment = encodeURIComponent(edit.getContent());
        }
        if($.trim(comment) == ""){
          alert("请填写审批意见");
          return false;
        }
        var vActionUrl="<%=path%>/com/orderEntity/back?comment="+comment+"&curDutyId="+$('#curDutyId').val();
        var data={keyId:$("input#keyId").val()};
        __ajax_post(vActionUrl,data,function(pdata){
          __toastr(pdata);
          $("#apply-re-common").trigger("click");
        });
      });
      //否决
      $("#left_foot_btn_deny").off("click").on("click",function(){
        var comment = "";
        if(edit != null){
          comment = encodeURIComponent(edit.getContent());
        }
        if($.trim(comment) == ""){
          alert("请填写审批意见");
          return false;
        }
        var vActionUrl="<%=path%>/com/orderEntity/deny?comment="+comment+"&curDutyId="+$('#curDutyId').val();
        var data={keyId:$("input#keyId").val()};
        __ajax_post(vActionUrl,data,function(pdata){
          __toastr(pdata);
          $("#apply-re-common").trigger("click");
        });
      });
    });

    //流程信息展开
    $('#flow,#next').click(function(){
      if($(this).hasClass("right")){
        $(this).removeClass("right").addClass("down");
        $(this).parent(".f_title").next("div.f_content").show();
      }else{
        $(this).removeClass("down").addClass("right");
        $(this).parent(".f_title").next("div.f_content").hide();
      }
    });

  });

  //to实施跟踪
  var table_global_width=0;
  $("#other2").click(function(){
    var parentId=$("#form_order_input #keyId").val();
    if (table_global_width == 0) {
      table_global_width = $("#s1").is(":visible") ? $("#s1").width() : $("#s2").width();
    }
    $('div').data("table_global_width", table_global_width);
    loadURL("<%=path%>/com/orderTrack/toList?parentId="+parentId,$('#s2'));
  });

  //to完成确认
  $("#other3").click(function(){
    var stateNum="${order.numStatus}";
    if(stateNum!=2){
      alert("该订单还没有完成");
      $(this).parent().addClass("disabled");
      return false;
    }else{
      var keyId=$("#form_order_input #keyId").val();
      loadURL("<%=path%>/com/orderEntity/finishRead/"+keyId,$('#s3'));
    }
  });

  // 附件显示
  readLoad({
    objId:"filename",
    entityName:"fileIds",
    sourceId:"fileId"
  });

  //编辑
  $("a[key='ajax_edit']").unbind("click").bind("click",function(){
    loadURL("<%=path%>/com/orderEntity/input?keyId="+$("#keyId").val()+"&draft="+draft+"&todo="+todo+"&remind="+remind+"&record="+record+"&index="+index,$('#page-content'));
  });


  //返回视图
  $("#apply-re-common").click(function(){

    if(index==1){
      loadURL("menu/dashboard",$('#page-content'));
    }else if(todo==1){
      loadURL("menu/toDo",$('#page-content'));
    }else if(remind==1){
      loadURL("menu/remind",$('#page-content'));
    }else if(record==1){
      loadURL("menu/taskRecord?type=1",$('#page-content'));
    }else if(record==2){
      loadURL("menu/taskRecord?type=2",$('#page-content'));
    }else if(draft==1){
      loadURL("menu/draft",$('#page-content'));
    }else{
      returnToHashUrl()
    }

  });

</script>